%% 
addpath H:\teach\ComputerVision\matlab

addpath E:\CompyVision

%%
i = teachimage('mantelpiece.bmp');
%%
i = teachimage('chess1.bmp');
%%
i = teachimage('edin_lib.bmp');
%%
i = cv2007image('car',1);

%%
i = cv2007image('car',2);

%%
i = cv2007image('car',3);

%%
i = cv2007image('car',4);

%%
i = cv2007image('car',5);

%%
i = cv2007image('car',6);
%%
i = cv2007image('cat',1);
%%
i = cv2007image('cat',2);
%%
i = cv2007image('cat',3);
%%
i = cv2007image('cat',4);
%%
i = cv2007image('cat',5);
%%
i = cv2007image('cat',6);
i(60:80,15:35) = 0;
imshow(i);

%% Using canny edge detection then finding peaks

x = edge(i,'canny',[],2);
figure;
imshow(x);
figure;
imshow(i);
[r,c,v] = findpeaks(x);
hold on;

plot(c,r,'g*');
%% Using canny edge detection, gaussian mask, then finding peaks

x = edge(i,'canny',[],3);    % Sigma 3 to get rid of fine detail

j = double(x);

mask = fspecial('gaussian',100,4);  %Lower sigma to increase detail/points 
Imout = convolve2(j,mask,'same'); 

figure;
imshow(i);


[r,c,v] = findpeaks(Imout); % add thresh for r & c 

ok = v > 0.09; % play around to change thresh
r = r(ok);
c = c(ok);

hold on;
plot(c,r,'g*');

figure;
imshow(Imout,[]);

%% Using gaussian mask then finding peaks 

mask = fspecial('gaussian',100,5); % Lower sigma for more detail/points
Imout = convolve2(i,mask,'same');

figure;
imshow(i);

[r,c,v] = findpeaks(-Imout); % negative image to find correct peaks
hold on;

plot(c,r,'g*');

figure;
imshow(-Imout,[]);

%% Use gaussian mask, then 'log' edge detection, then gaussian mask, then find peaks.

mask = fspecial('gaussian',60,3);
Image = convolve2(i,mask,'reflect');

figure;
imshow(Image)

x = edge(Image, 'canny', [], 3); 
[r,c] = size(Image);
j = ones(r,c) .* x;

figure;
imshow(j);

mask = fspecial('gaussian',60,12);
Imout = convolve2(j,mask,'same');

figure;
imshow(Imout,[]);

figure;
imshow(i);

[r,c,v] = findpeaks(Imout);
hold on;
plot(c,r,'g*');
